<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var currentValue = document.all.parentId.value;
		var rangeValue = document.getElementById("rangeValue");
		
		if(currentValue == "0"){
			alert("<fmt:message key='range.message.industry'/>");
			return false;
		}
		
		if(rangeValue.value == ""){
			alert("<fmt:message key='range.lable.rangeValue'/><fmt:message key='common.message.empty'/>");
			return false;
		}
		
		return true;
	}

	function back(){
		window.location.href = "./dictionarySet.do";
		window.location.target = "main";
	}
	
	function change(){
		var currentValue = document.all.parentId.value;
		if(currentValue != "0"){
			var id = "<c:out value='${id}'/>";
			document.addIndustryDetailForm.action = "./recordRange.do?action=preAddIndustryDetail&id="+id+"&parentId="+currentValue;
			document.addIndustryDetailForm.target = "main";
			document.addIndustryDetailForm.submit();
		}
	}
	
	function save(){
		if(checkForm()){
			document.addIndustryDetailForm.action = "./recordRange.do?action=addIndustryDetail";
			document.addIndustryDetailForm.target = "main";
			document.addIndustryDetailForm.submit();
		}
	}
	
	function deleteRange(id){
		document.addIndustryDetailForm.action = "./recordRange.do?action=deleteIndustryDetailRange&rangeId="+id;
		document.addIndustryDetailForm.target = "main";
		document.addIndustryDetailForm.submit();
	}
	
	function initPage(){
		if("<c:out value='${result}'/>" == 1){
			alert("<fmt:message key='common.message.addSuccess'/>");
		}else if("<c:out value='${result}'/>" == 3){
			alert("<fmt:message key='common.message.deleteSuccess'/>");
		}
		
		if("<c:out value='${repeat}'/>" == 1){
			alert("<fmt:message key='common.message.addFail'/><fmt:message key='dic.message.rangeValue'/><fmt:message key='common.message.exist'/>");
		}
	}
-->
</script>
</head>
<body onload="initPage()">
<form name="addIndustryDetailForm" action="" method="post">
	<a class="common_title">>> <fmt:message key='range.title.base'/></a>
	
	<div class="tools">
		<c:if test="${isSettingsDictionary == 1}">
		<a class="save" href="javascript:save();" title="<fmt:message key='common.button.save'/>" hidefocus="true"><fmt:message key='common.button.save'/></a>&nbsp;&nbsp;&nbsp;&nbsp;
		</c:if>
		<a class="back" href="javascript:back();" title="<fmt:message key='common.button.back'/>" hidefocus="true"><fmt:message key='common.button.back'/></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	</div>

	<table class="table_input1" height="30" cellpadding="0" cellspacing="0">
		<tr>
			<td width="1%"></td>
			<td class="" width="10%"><fmt:message key='range.lable.industry'/><fmt:message key='common.sign'/></td>
			<td class="">
				<select id="parentId" name="parentId" onchange="change()">
					<option value="0">----------<fmt:message key='common.select.option'/>----------</option>
					<c:forEach var="recordRange" items="${industryRanges}">
					<option value="${recordRange.id}" <c:if test='${recordRange.id == paretnRangeId}'>selected</c:if> >${recordRange.rangeValue}</option>
					</c:forEach>
				</select>
			</td>
		</tr>
		<tr>
			<td width="1%"></td>
			<td class="" width=""><fmt:message key='range.lable.rangeValue'/><fmt:message key='common.sign'/></td>
			<td class="">
				<input id="rangeValue" name="rangeValue" class="input_long" type="text"/>
				<input id="dataDictionaryId" name="dataDictionaryId" type="hidden" value="${dataDictionary.id}"/>
				<input id="recordCode" name="recordCode" type="hidden" value="${dataDictionary.recordCode}"/>
			</td>
		</tr>
	</table>
	
	<table class="table_style" style="text-align: center;">
		<tr>
			<td class="title" colspan="2">
				<fmt:message key='range.lable.currentRecord'/><fmt:message key='common.sign'/>
				<c:choose>
					<c:when test="${language == 2}">${dataDictionary.currentRecordEn}</c:when>
					<c:otherwise>${dataDictionary.currentRecord}</c:otherwise>
				</c:choose>
			</td>
		</tr>
		<tr>
			<td class="title4"><fmt:message key='range.lable.rangeValue'/></td>
			<td class="title4" width="8%"><fmt:message key='common.lable.operate'/></td>
		</tr>
		<c:forEach var="recordRange" items="${recordRanges}">
		<tr>
			<td>${recordRange.rangeValue}</td>
			<td>
				<img class="btn_img" src="./images/a_del.gif" onclick="deleteRange('${recordRange.id}')" title="<fmt:message key='common.button.delete'/>">&nbsp;&nbsp;
			</td>
		</tr>
		</c:forEach>
	</table>
</form>
</body>
</html>